clear all

global  folderfig foldermats eta  xij_for_investor homedealer kappa day quantityrobus loyaltyinW keepall largetrade tradesize fej zerobenefit loyalty 

folderfig   = '/Users/wittwer/Dropbox/5_Jason and Milena/data/Matlab_JMP_2R1/main_estimation_submission2R1/3_figures';
foldermats  = '/Users/wittwer/Dropbox/5_Jason and Milena/data/Matlab_JMP_2R1/main_estimation_submission2R1/2_output';


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PARAMETERS TO CHOSE:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
%choose whether loyalty benefit is 0 or not and whether it counts for welfare
loyalty=1;
    %=0 set r=0
    %=1 let r>0

loyaltyinW=1;
    %=0 for all benchmark model and homedealer model when homedealer benefit does not enter welfare
    %=1 for homedealer model when homedealer benefit enters welfare
 
%Below parameters don't change in current draft    
homedealer=1;keepall=1;largetrade=1;tradesize=0;fej=1;zerobenefit=0;day=1;quantityrobus=0;eta = 0;
kappa=0.1; 
    %=0.1 for all CF but CF=7 
    %=0 for CF=7 
   
if zerobenefit ==1 %for CF use the small trades only 
    homedealer=0; day=1; keepall=1; largetrade=1; tradesize=0; quantityrobus=0;
end 
if homedealer==1, xij_for_investor=0;  else,  xij_for_investor=1;  end 
 
pool = 0; 
    %=1, use estimates when dealers are sophisticated
    %=0, use estimates when dealers set quotes assuming that there is a representative consumer

%Counterfactuals
CFvec=[3 5 4 6 1 2 7 8 9 10 11 12 13 14 15  16 17 18 -1 -2  -3]; 
    
    %CF=-3 no access to institutional investors  

    %CF = -2 status quo but with q=v and sigma=0
    %CF = -1 status quo but with q=v 
 
    %CF=3 access to R and I, estimated costs
    %CF=5 access to R and I, eliminate platform fee
    %CF=4 access to R and I ,eliminate all costs
    %CF=6 access to R and I,eliminate all costs plus r=0
    
    %CF=7 estimated costs, shut down platform access (for instituitionals only)
          %set flexible=0
          
    %CF=8-11: Frictionless platform (q=v and sigma =0)
          %set flexible=0
          %CF=8:  at estimated cost 
          %CF=9:  eliminate platform fee
          %CF=10: eliminate platform fee and r=0
          %CF=11: eliminate all platform cost
    
    %CF=12-15: Truthful quotes (v=q) but sigma as estimated
          %set flexible=0
          %CF=12:  at estimated cost 
          %CF=13: eliminate platform fee
          %CF=14: eliminate platform fee and r=0
          %CF=15: eliminate all platform cost
    
    %CF = 16-18: All on the platform
          %16 with quotes
          %17 with q=v but sigma>0
          %18 with q=v and sigma=0


plots=0; %no figures 
for cf=[21 1 2 16 20 8 9 18]
    
    %To create Table 6 and Appendix Table 5 use the following sequence of cf's 
    %(moving left to right in a col before moving down), 
    
    %With loyalty (loyaltyinW=1, loyalty=1) and imperfect competition: 
        %Decentralized:  21
        %Access to I:     1 - but use the welfare of the SQ (this is in "Total Expected welfare: x bps out of SQ-WELFARE bps)
        %Access to IR:    1
        %No fee:          2
        %Central:         16
   
    %With loyalty  (loyaltyinW=1, loyalty=1) and perfect competition  
        %Access to I:      20
        %Access to IR:     8
        %No fee:           9 
        %Central:          18
        
    %Switching cost - same sequence as above but with loyaltyinW=0
    %No loyalty - same sequence as above but with loyaltyinW=0 and loyalty=0

    if cf==1 || cf==2 || cf==3 ||  cf==4 || cf==16 , flexible=1; else flexible=0; end 

    if CFvec(cf)>0
         for side=[1]
                 [WCF,WSQ, Weffi] = welfare_fun(side, CFvec, cf, flexible, plots); 
         end 
    else 

        for side=[1]
                 [WCF,WSQ, Weffi] = welfare_fun_add(side, CFvec, cf, flexible, plots); 
        end 

    end 
end


